spb/company-atlas
Public
Python 66.3%
TypeScript 22.7%
JavaScript 8.6%
HTML 1.4%
CSS 0.7%
1import type { Metadata } from 'next';2import { notFound } from 'next/navigation';3import { api, ApiError } from '@/lib/api';4import { countryName } from '@/lib/countries';5import { SITE_NAME } from '@/lib/site';67/** Existence check lives in the segment layout (Next 16: a root `loading.tsx` would soft-404). */8async function load(slug: string) {9 try {10 return await api.company(slug);11 } catch (e) {12 if (e instanceof ApiError && e.notFound) notFound();13 return null;14 }15}1617export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {18 const { slug } = await params;19 const c = await load(slug);20 if (!c) return { title: 'Company' };21 const about = c.profile?.description ?? c.description ?? '';22 const desc = `${c.display_name} (${c.canonical_domain}${c.country ? `, ${countryName(c.country)}` : ''}): ${c.counts.sensors} active sensors, ${c.counts.events} structured events, ${c.counts.changes} historical changes. ${about.length > 220 ? `${about.slice(0, 219).trimEnd()}…` : about}`.trim();23 return {24 title: `${c.display_name} — sensors, timeline and history`,25 description: desc,26 alternates: { canonical: `/company/${c.slug}` },27 openGraph: { title: `${c.display_name} | ${SITE_NAME}`, description: desc, type: 'profile' },28 };29}3031export default async function CompanyLayout({ params, children }: { params: Promise<{ slug: string }>; children: React.ReactNode }) {32 const { slug } = await params;33 await load(slug);34 return <>{children}</>;35}36